home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / Asm / Demos / BouncingBobs.s next >
Encoding:
Text File  |  1997-05-02  |  8.1 KB  |  362 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Bouncing BOB's Demo
  3. ;-------------------
  4. ;This is a demonstration of bouncing bobs, an extension of the original
  5. ;Raining BOBs demo.
  6. ;
  7. ;It runs in high-resolution + lace with a total of 35 16x16 bobs at 50 FPS
  8. ;('020+FAST).
  9.  
  10.     INCDIR    "INCLUDES:"
  11.     INCLUDE    "games/games_lib.i"
  12.     INCLUDE    "games/games.i"
  13.  
  14. CALL    MACRO
  15.     jsr    _LVO\1(a6)
  16.     ENDM
  17.  
  18. MAX_IMAGES =    35
  19.  
  20.     SECTION    "BouncingBOBs",CODE
  21.  
  22. ;===========================================================================;
  23. ;                             INITIALISE DEMO
  24. ;===========================================================================;
  25.  
  26.     STARTGMS
  27.  
  28. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  29.     move.l    GMSBase(pc),a6
  30.     CALL    AllocBlitter
  31.     tst.l    d0
  32.     bne    .Error_Blitter
  33.  
  34.     lea    PIC_BobTags(pc),a1
  35.     CALL    LoadPic
  36.     tst.l    d0
  37.     beq.s    .Error_Picture
  38.  
  39.     move.l    PIC_Bobs(pc),a1
  40.     move.w    PIC_Planes(a1),GSPlanes+2
  41.     move.l    PIC_Palette(a1),GSPalette
  42.  
  43.     lea    ScreenTags(pc),a0
  44.     CALL    AddScreen
  45.     tst.l    d0
  46.     beq.s    .Error_Screen
  47.  
  48.     move.l    Screen(pc),a0    ;a0 = GameScreen
  49.     moveq    #2,d0    ;d0 = 2 buffers.
  50.     moveq    #MAX_IMAGES,d1    ;d1 = Maximum amount of images.
  51.     CALL    InitRestore
  52.     move.l    d0,Restorelist
  53.     beq.s    .Error_Restorelist
  54.  
  55.     lea    TAGS_Ball(pc),a1    ;Initialise the Ball mbob.
  56.     CALL    InitBob
  57.     tst.l    d0
  58.     beq.s    .Error_Ball
  59.  
  60.     lea    TAGS_Interlaced(pc),a1    ;Initialise "HiRes Interlaced" bob.
  61.     CALL    InitBob
  62.     tst.l    d0
  63.     beq.s    .Error_Laced
  64.  
  65.     CALL    ShowScreen
  66.  
  67.     bsr.s    Main
  68.  
  69. .ReturnToDOS
  70.     move.l    GMSBase(pc),a6
  71.     move.l    BOB_Interlaced(pc),a1
  72.     CALL    FreeBob
  73. .Error_Laced
  74.     move.l    MBOB_Ball(pc),a1
  75.     CALL    FreeBob
  76. .Error_Ball
  77.     move.l    Restorelist(pc),d0
  78.     CALL    FreeRestore
  79. .Error_Restorelist
  80.     lea    ScreenTags(pc),a0
  81.     CALL    DeleteScreen
  82. .Error_Screen
  83.     move.l    PIC_Bobs(pc),a1
  84.     CALL    FreePic
  85. .Error_Picture
  86.     CALL    FreeBlitter
  87. .Error_Blitter
  88.     MOVEM.L    (SP)+,A0-A6/D1-D7
  89.     moveq    #ERR_OK,d0
  90.     rts
  91.  
  92. ;===========================================================================;
  93. ;                                DEMO CODE
  94. ;===========================================================================;
  95.  
  96. Main:    move.l    GMSBase(pc),a6    ;a6 = GMSBase.
  97.     move.l    Screen(pc),a0    ;a0 = GameScreen.
  98.  
  99.     move.l    BOB_Interlaced(pc),a1    ;a1 = BOB to draw.
  100.     move.w    GS_ScrWidth(a0),d0
  101.     sub.w    BOB_Width(a1),d0
  102.     move.w    d0,BOB_XCoord(a1)
  103.     moveq    #BUFFER2,d0    ;d0 = Buffer 2.
  104.     CALL    DrawBob    ;>> = Draw the BOB
  105.     moveq    #BUFFER1,d0    ;d1 = Buffer 1.
  106.     CALL    DrawBob    ;>> = Draw the BOB
  107.  
  108.     moveq    #$00,d7
  109.     move.l    MBOB_Ball(pc),a1
  110.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  111.     move.w    MB_AmtEntries(a1),d2    ;a2 = Amount of entries.
  112.     subq.w    #1,d2    ;d2 = --1 for loop.
  113.     moveq    #$00,d3
  114.  
  115. .create    eor.w    #1,d3
  116.  
  117.     moveq    #8,d1    ;Set Y speed here.
  118.     CALL    FastRandom
  119.     addq.w    #2,d0
  120.     move.w    d0,BE_YSpeed(a2)
  121.  
  122.     move.w    #8,d1    ;Set X speed here.
  123.     CALL    FastRandom
  124.     addq.w    #1,d0
  125.     move.w    d0,BE_XSpeed(a2)
  126.  
  127.     tst.w    d3
  128.     beq.s    .posx
  129.     neg.w    BE_XSpeed(a2)
  130. .posx
  131.     move.w    GS_ScrHeight(a0),d1    ;Starting Y coordinate.
  132.     asr.w    #1,d1
  133.     CALL    FastRandom
  134.     asr.w    #1,d1
  135.     add.w    d1,d0
  136.     move.w    d0,BE_YCoord(a2)
  137.  
  138.     move.w    GS_ScrWidth(a0),d1    ;Starting X coordinate.
  139.     CALL    FastRandom
  140.     move.w    d0,BE_XCoord(a2)
  141.  
  142.     moveq    #12,d1
  143.     CALL    FastRandom
  144.     move.w    d0,BE_Frame(a2)
  145.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  146.     move.w    #1,BE_FChange(a2)
  147.     move.w    d3,BE_Locked(a2)
  148.  
  149.     lea    NBE_SIZEOF(a2),a2
  150.     dbra    d2,.create
  151.     bra.s    Loop
  152.  
  153. .Sets    dc.b    0,0,0,0
  154.     dc.b    1,1,1,1
  155.     dc.b    2,2,2,2
  156.  
  157. ;---------------------------------------------------------------------------;
  158.  
  159. Loop:    addq.w    #1,d7
  160.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  161.     move.w    MB_AmtEntries(a1),d2
  162.     subq.w    #1,d2
  163. .update    bsr.s    UpdateBob
  164.     lea    NBE_SIZEOF(a2),a2
  165.     dbra    d2,.update
  166.  
  167.     move.l    Restorelist(pc),a1    ;a1 = Restorelist.
  168.     CALL    Restore
  169.  
  170.     move.l    a1,a2    ;a2 = Restorelist.
  171.     move.l    MBOB_Ball(pc),a1    ;a1 = BOB to draw.
  172.     moveq    #BUFFER2,d0
  173.     CALL    DrawBob    ;>> = Draw the BOB
  174.  
  175.     CALL    WaitVBL    ;>> = Wait for VBL.
  176.     CALL    SwapBuffers    ;>> = Swap the buffers.
  177.  
  178.     moveq    #JPORT1,d0    ;d0 = JoyPort2
  179.     moveq    #JT_ZBXY,d1    ;d1 = Bit switch type.
  180.     CALL    ReadJoyPort    ;>> = Go get port status.
  181.     btst    #MB_LMB,d0    ;d0 = LMB pressed?
  182.     beq.s    Loop    ;>> = No.
  183.     rts
  184.  
  185. ;===========================================================================;
  186. ;                               UPDATE A BOB
  187. ;===========================================================================;
  188. ;Function: Moves the entity according to its internal settings.
  189. ;Requires: a1 = Bob structure.
  190. ;       a2 = Entry to update.
  191.  
  192. GRAVITY =    1
  193.  
  194. UpdateBob:
  195.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  196.     add.w    BE_YSpeed(a2),d0    ;d0 = (YCoord)+YSpeed
  197.     cmp.w    GS_ScrHeight(a0),d0    ;d0 = Should this bob bounce?
  198.     blt.s    .NoBounce    ;>> = No.
  199.     neg.w    BE_YSpeed(a2)    ;a2 = Bounce the bob!
  200.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the bob down.
  201.     bra.s    .CheckX
  202. .NoBounce
  203.     move.w    d0,BE_YCoord(a2)    ;d0 = Save the change.
  204.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the bob down.
  205.  
  206. .CheckX    move.w    BE_XCoord(a2),d0
  207.     add.w    BE_XSpeed(a2),d0
  208.     cmp.w    GS_ScrWidth(a0),d0
  209.     bcs.s    .NoXBounce
  210.     neg.w    BE_XSpeed(a2)
  211.     bra.s    .Animate
  212. .NoXBounce
  213.     move.w    d0,BE_XCoord(a2)
  214.  
  215. ;---------------------------------------------------------------------------;
  216.  
  217. .Animate
  218.     tst.w    BE_Locked(a2)
  219.     beq.s    .exit
  220.     move.w    d7,d6
  221.     and.w    #%00000011,d6
  222.     bne.s    .exit
  223.     move.w    BE_FChange(a2),d1
  224.     bgt.s    .Positive
  225.  
  226. .Negative
  227.     cmp.w    #1,BE_Set(a2)
  228.     bgt.s    .NBlue
  229.     beq.s    .NGreen
  230. .NRed    add.w    d1,BE_Frame(a2)
  231.     tst    BE_Frame(a2)
  232.     bge.s    .exit
  233.     move.w    #1,BE_FChange(a2)
  234.     clr.w    BE_Frame(a2)
  235.     rts
  236. .NGreen    add.w    d1,BE_Frame(a2)
  237.     cmp.w    #4,BE_Frame(a2)
  238.     bge.s    .done
  239.     move.w    #1,BE_FChange(a2)
  240.     move.w    #4,BE_Frame(a2)
  241.     rts
  242. .NBlue    add.w    d1,BE_Frame(a2)
  243.     cmp.w    #8,BE_Frame(a2)
  244.     bge.s    .done
  245.     move.w    #1,BE_FChange(a2)
  246.     move.w    #8,BE_Frame(a2)
  247. .exit    rts
  248.  
  249. .Positive
  250.     cmp.w    #1,BE_Set(a2)
  251.     bgt.s    .PBlue
  252.     beq.s    .PGreen
  253. .PRed    add.w    d1,BE_Frame(a2)
  254.     cmp.w    #3,BE_Frame(a2)
  255.     ble.s    .done
  256.     move.w    #-1,BE_FChange(a2)
  257.     move.w    #2,BE_Frame(a2)
  258.     rts
  259. .PGreen    add.w    d1,BE_Frame(a2)
  260.     cmp.w    #7,BE_Frame(a2)
  261.     ble.s    .done
  262.     move.w    #-1,BE_FChange(a2)
  263.     move.w    #6,BE_Frame(a2)
  264.     rts
  265. .PBlue    add.w    d1,BE_Frame(a2)
  266.     cmp.w    #11,BE_Frame(a2)
  267.     ble.s    .done
  268.     move.w    #-1,BE_FChange(a2)
  269.     move.w    #10,BE_Frame(a2)
  270. .done    rts
  271.  
  272. ;===========================================================================;
  273. ;                                  DATA
  274. ;===========================================================================;
  275.  
  276.   STRUCTURE    NBE,BE_SIZEOF    ;Definition for the mutated Entry-
  277.     WORD    BE_XSpeed    ;list in the Ball bob.
  278.     WORD    BE_YSpeed
  279.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  280.     WORD    BE_FChange
  281.     WORD    BE_Locked
  282.     LABEL    NBE_SIZEOF
  283.  
  284. Restorelist:    dc.l  0
  285.  
  286. ScreenTags:    dc.l  TAGS_GAMESCREEN
  287. Screen:        dc.l  0
  288.         dc.l  GSA_Rasterlist,Rasterlist
  289.         dc.l  GSA_ScrWidth,640
  290.         dc.l  GSA_ScrHeight,512
  291.         dc.l  GSA_Attrib,DBLBUFFER
  292.         dc.l  GSA_ScrMode,HIRES|LACED
  293.         dc.l  GSA_Planes
  294. GSPlanes:    dc.l  0
  295.         dc.l  GSA_Palette
  296. GSPalette:    dc.l  0
  297.         dc.l  TAGEND
  298.  
  299. Rasterlist:    COLOURLIST  300,30,00,.colours ;Line, Skip, Colnum, Colours.
  300.         RASTEND
  301. .colours    dc.l  $100000,$200000,$300000,$400000,$500000,$600000,$700000
  302.         dc.l  -1
  303.  
  304. ;---------------------------------------------------------------------------;
  305.  
  306. PIC_BobTags:    dc.l  TAGS_PICTURE
  307. PIC_Bobs:    dc.l  0
  308.         dc.l  PCA_Options,VIDEOMEM|GETPALETTE
  309.         dc.l  PCA_File,.file
  310.         dc.l  TAGEND
  311. .file        dc.b  "GMS:demos/data/PIC.HRPulse",0
  312.         even
  313.  
  314. ;---------------------------------------------------------------------------;
  315.  
  316. TAGS_Ball:    dc.l  TAGS_MBOB
  317. MBOB_Ball:    dc.l  0
  318.         dc.l  MBA_AmtEntries,MAX_IMAGES
  319.         dc.l  MBA_Framelist,.frames
  320.         dc.l  MBA_Width,16
  321.         dc.l  MBA_Height,16
  322.         dc.l  MBA_EntryList,Images
  323.         dc.l  MBA_Attrib,CLIP|GENMASKS|CLEAR|CLRNOMASK
  324.         dc.l  MBA_PictureTags,PIC_BobTags
  325.         dc.l  MBA_EntrySize,NBE_SIZEOF
  326.         dc.l  TAGEND
  327.  
  328. .frames        dc.w  00,16*0,0,0    ;RED
  329.         dc.w  00,16*1,0,0
  330.         dc.w  00,16*2,0,0
  331.         dc.w  00,16*3,0,0
  332.         dc.w  16,16*0,0,0    ;GREEN
  333.         dc.w  16,16*1,0,0
  334.         dc.w  16,16*2,0,0
  335.         dc.w  16,16*3,0,0
  336.         dc.w  32,16*0,0,0    ;BLUE
  337.         dc.w  32,16*1,0,0
  338.         dc.w  32,16*2,0,0
  339.         dc.w  32,16*3,0,0
  340.         dc.l  -1
  341.  
  342. ;---------------------------------------------------------------------------;
  343.  
  344. TAGS_Interlaced    dc.l  TAGS_BOB
  345. BOB_Interlaced:    dc.l  0
  346.         dc.l  MBA_Framelist,.frames
  347.         dc.l  MBA_Width,96
  348.         dc.l  MBA_Height,7
  349.         dc.l  MBA_Attrib,GENMASKS
  350.         dc.l  MBA_PictureTags,PIC_BobTags
  351.         dc.l  TAGEND
  352.  
  353. .frames        dc.w  000,16*4,0,0    ;0 X/Y Graphic, X/Y Mask
  354.         dc.l  -1
  355.  
  356. ;---------------------------------------------------------------------------;
  357.  
  358.     SECTION    Images,BSS
  359.  
  360. Images    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  361.  
  362.